package net.wsfcp.android.http.mvp.presenter;

import net.wsfcp.android.base.BasePresenter;
import net.wsfcp.android.bean.requestbean.ReqCityBean;
import net.wsfcp.android.bean.requestbean.ReqCreateAddressBean;
import net.wsfcp.android.bean.resultbean.CityBean;
import net.wsfcp.android.http.mvp.contract.AddressContract;
import net.wsfcp.android.http.mvp.model.AddressModel;
import net.wsfcp.android.http.mvp.IModel;
import net.wsfcp.android.ui.view.my.fragment.AddAddressFragment;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by Shaoboyang on 2018/12/14.
 */
//新增地址
public class CreateAddressPresenter extends BasePresenter<AddAddressFragment> implements
        AddressContract.CreateAddressPresenter {

    @Override
    public void createAddress(ReqCreateAddressBean bean) {
        if (!getIView().checkNull()) {
            ((AddressModel) getiModelMap().get("create")).createAddress(bean, new AddressModel
                    .CreateAddressInfoHint() {
                @Override
                public void createAddressSuccessInfo() {
                    getIView().createAddressSuccess();
                }

                @Override
                public void createAddressFailInfo(String str) {
                    getIView().createAddressFail(str);
                }


            });
        }
    }

    @Override
    public void getCity(ReqCityBean bean) {

        ((AddressModel) getiModelMap().get("city")).getCity(bean, new AddressModel
                .GetCityInfoHint() {
            @Override
            public void getCitySuccessInfo(ArrayList<CityBean> beans) {
                getIView().getCitySuccess(beans);
            }

            @Override
            public void getCityFailInfo(String str, int type) {
                getIView().getCityFail(str, type);
            }


        });

    }


    @Override
    public HashMap<String, IModel> getiModelMap() {
        return loadModelMap(new AddressModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String, IModel> map = new HashMap<>();
        map.put("create", models[0]);
        map.put("city", models[0]);
        return map;
    }





}
